<template>
    <div>
        <a href="/Add"></a>
        门店名称:
        <input type="text" v-model="index.name">
        门店状态:
        <select v-model="index.xia">
            <option value="0">请选择</option>
            <option v-for="a in datas":value="a.hoteId">{{a.hoteName}}</option>
        </select>
        <input type="button" value="查询" @click="getdata">
     <table class="table">
        <thead>
            <tr>
                <td>ID</td>
                <td>门店名称</td>
                <td>营业时间</td>
                <td>客服电话</td>
                <td>地址</td>
                <td>门店图片</td>
                <td>门店状态</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="a in data">
                <td>{{a.userId}}</td>
                <td>{{a.userName}}</td>
                <td>{{a.userTime?.substring(0.5)}}至{{a.userTimes?.substring(0.5)}}</td>
                <td>{{a.userPhone}}</td>
                <td>{{a.userAddress}}</td>
                <td>
                    <img :src="'https://localhost:7186/' + a.userImg" style="width: 80px; height: 60px;">
                </td>
                <td :style="a.hoteId==1?'color:green':'color:red'">{{a.hoteId==1?"启用":"禁用"}}</td>
                <td><input type="button" value="删除" @click="delget(a.userId)">
                    <input type="button" value="编辑" @click="upd(a.userId)">
                </td>
            </tr>
        </tbody>
     </table>

<input type="button" value="首页" @click="fenye(1)">
<input type="button" value="上一页" @click="fenye(2)">

<input type="button" v-for="a in indexs.pagecount":value="a" @click="shuzi(a)">

<input type="button" value="下一页" @click="fenye(3)">
<input type="button" value="尾页" @click="fenye(4)">

<input type="number" v-model="index.pageindex">
<input type="button" value="跳转" @click="tiao">

<select v-model="index.pagesize" @click="set">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
</select>

    </div>
</template>

<script setup lang="ts">
import router from '@/router';
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';

const fenye=(val:any)=>{

if(val==1){
index.value.pageindex=1;
getdata()
}
if(val==2 && index.value.pageindex>1){
index.value.pageindex--;
getdata()
}
if(val==3 && index.value.pageindex<indexs.value.pagecount){
index.value.pageindex++;
getdata()
}
if(val==4){
index.value.pageindex=indexs.value.pagecount
getdata()
}
}

const tiao=()=>{
    if(index.value.pageindex<1 || index.value.pageindex>indexs.value.pagecount){
    alert("页码无效");
    index.value.pageindex=1;
    return;
    }
    getdata()
}

const shuzi=(val:any)=>{
    index.value.pageindex = val;
    getdata()
}

const set=()=>{
    getdata()
}

const data = ref([{
      "userId": 4,
      "hoteId": 2,
      "userName": "string",
      "userTime": "2025-06-06 00:00:00.0000000",
      "userTimes": "2025-06-11 00:00:00.0000000",
      "userPhone": "string",
      "userAddress": "string",
      "hoteName": "禁用",
      "userShan": false,
      "delTime": "2025-06-05T12:28:52.911",
      "upTime": "2025-06-05T12:28:52.911",
      "userImg": "/Img/202529051.png"
    }])

onMounted(()=>{
    getdata()
    xiala()
})

const datas = ref([{
    "hoteId": 0,
    "hoteName": "string"
}])

const xiala=()=>{
    axios.get("/api/Hote/Show").then(res=>{
    datas.value = res.data;
    })
}

const index = ref({
    pageindex : 1,
    pagesize : 3,
    name : "",
    xia : 0
})

const indexs = ref({
    count : 0,
    pagecount : 0
})

const getdata=()=>{
    axios.get("/api/User/GetAllAsync",{params:index.value}).then(res=>{
    data.value = res.data.pagecount

    indexs.value.count = res.data.count
    indexs.value.pagecount = Math.ceil(indexs.value.count/index.value.pagesize)
    })
}

const delget=(val:any)=>{
if(!confirm('你确定要删除吗?')){
return;
}
axios.get("/api/User/DelStore",{params:{id:val}}).then(res=>{
if(res.data>0){
alert('删除成功')
}
else{
alert('删除失败')
}
})
}

const upd=(mid:any)=>{
    router.push({path:'/Fan',query:{id:mid}})
}
</script>

<style scoped>

</style>